<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page"/>

<fmt:setBundle basename="ApplicationMessage"/>
<fmt:setLocale value="zh_CN"/>

<!DOCTYPE html>
<html lang="zh-CN">
<head>

    <%@ include file="/WEB-INF/include/meta.jsp" %>
    <%@ include file="/WEB-INF/include/css.jsp" %>

</head>

<body class="ms-theme-blue">

<%@ include file="/WEB-INF/include/header.jsp" %>
<%@ include file="/WEB-INF/include/submenu.jsp" %>

<div class="container-fluid ms-container has-ms-sidemenu">

    <ol class="ms-breadcrumb breadcrumb">
        <li class="active">客户管理 &nbsp;-&nbsp;客户列表</li>
    </ol>

    <div class="ms-content-layout has-operation">

        <div class="ms-operation-bar no-margin no-bottom-border clearfix">
            <div class="ms-operation-group pull-right">
                <a href="${ctx.host}/clients/add" class="btn ms-btn ms-btn-blue" data-target="#add" data-toggle="modal">
                    <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加
                </a>
                <a href="${ctx.host}/clients/export" class="btn ms-btn ms-btn-blue" data-target="#export"
                   data-toggle="modal">
                    <i class="glyphicon glyphicon-download-alt"></i>&nbsp;&nbsp;导出
                </a>
            </div>
        </div>

        <table class="table table-hover ms-table">
            <thead>
            <tr>
                <th>序号</th>
                <th>EMAIL</th>
                <th>联系人</th>
                <th>联系手机</th>
                <th>客户类型</th>
                <th>公司名称</th>
                <th>录入人</th>
                <th>代理</th>
                <th>录入时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            <c:forEach var="c" items="${clients}" varStatus="status">
                <tr>
                    <td>${status.index + 1}</td>
                    <td>${c.email}</td>
                    <td>${c.contacts}</td>
                    <td>${c.phone}</td>
                    <td><c:forEach items="${c.types}" var="t"> ${t.description} </c:forEach></td>
                    <td>${c.companyName}</td>
                    <td>${c.principal.name}</td>
                    <td>${c.agent.name}</td>
                    <td><fmt:formatDate value="${c.createTime}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                    <td>
                        <a href="${ctx.host}/clients/${c.id}">详情</a>
                        <c:if test="${c.havingAgent()}">
                            <a href="${ctx.host}/clients/${c.id}/bind-agent" data-toggle="modal" data-target="#bind-agent"> 修改代理</a>
                        </c:if>
                        <c:if test="${!c.havingAgent()}">
                            <a href="${ctx.host}/clients/${c.id}/bind-agent" data-toggle="modal" data-target="#bind-agent"> 添加代理</a>
                        </c:if>

                    </td>
                </tr>
            </c:forEach>

            </tbody>
            <tfoot>
            <tr>
                <td colspan="10" class="no-vertical-padding">
                    <div class="pull-left">
                        <jsp:include page="/WEB-INF/include/page.jsp">
                            <jsp:param name="url" value="${ctx.host}/clients"/>
                            <jsp:param name="queryString" value="${queryString}"/>
                        </jsp:include>
                    </div>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>

<%@ include file="/WEB-INF/include/footer.jsp" %>
<%@ include file="/WEB-INF/include/script.jsp" %>

<d:resource type="script" root="${ctx.resource}/build" src="js/page/data/client-list.js"/>
<script type="text/javascript">
    require(['page/data/client-list'], function (page) {
        page.init();
    })
</script>

</body>
</html>